//
//  CZTabBarViewController.swift
//  Weibo
//
//  Created by 董松 on 16/2/26.
//  Copyright © 2016年 董松. All rights reserved.
//

import UIKit

 /// TabBar分析 1.自定义TabBar 2.



class CZTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        //只读－不能修改
        //1.添加一个view
        //2.KVC
        
        let tabbar = CZTabBar()
        
        //通过KVC成功的给只读属性赋值
        setValue(tabbar, forKey: "tabBar")
        
        //实现按钮的点击
        tabbar.composeButton.addTarget(self, action: "showPublish", forControlEvents: UIControlEvents.TouchUpInside)
        
        //添加控制器
        addChildViewController()
        
        
        
    }

    //MARK:--按钮的点击方法
    func showPublish(){
        print("点了我")
    }
    
///  addChildViewController -- 重载   没有参数
    
    func addChildViewController() {
        addChildViewController(CZHomeViewController(), title:"首页", image:"tabbar_home")
        addChildViewController(CZMessageViewController(), title: "消息", image: "tabbar_message_center")
        addChildViewController(CZFindViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(CZSettingViewController(), title: "设置", image: "tabbar_profile")
    }
    
    //给addChildViewController 方法添加参数  重载
    
    func addChildViewController(childController: UIViewController,title: String,image:String) {
        //创建一个home控制器
        //let home = CZHomeViewController()
        //设置文字
        childController.title = title
        //设置图片
        childController.tabBarItem.image = UIImage(named: image)
        //字符串进行拼接
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        //如果不改变tintcolor的颜色，系统默认渲染蓝色
//        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        addChildViewController(UINavigationController(rootViewController: childController))
    }
    
    
    

}
